<?php

/**
 * uniBoard ACP Edit User
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-20 21:23:27 +0000 (Mon, 20 Sep 2010) $
 * $Revision: 64 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class action_edit_user{
	
	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore		= NULL;
	
	/**
	 * Our api
	 *
	 * @var object
	 */
	
	private $api			= NULL;
	
	/**
	 * Non-admin editing root admin?
	 *
	 * @var false
	 */
	
	private $root_secure	= false;
	
	/**
	 * Avaiable Groups
	 *
	 * @var array
	 */
	
	private $groups			= array();
	
	/**
	 * Avaiable Ranks
	 *
	 * @var array
	 */
	
	private $ranks			= array();
	
	/**
	 * Avaiable Masks
	 *
	 * @var array
	 */
	
	private $masks			= array();
	
	/**
	 * Avaiable Languages
	 *
	 * @var array
	 */
	
	private $languages		= array();
	
	/**
	 * Avaiable Styles
	 *
	 * @var array
	 */
	
	private $styles			= array();
	
	// ------------------------------------------------------------------------

	/**
	 * Initialise Action
	 *
	 * @param object $appCore
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;
		
		// Create API
		$this -> api = new api_user( $appCore, $appCore -> _REQ('user'));
		
		// User found?
		$this -> root_secure = $this -> api -> data_loaded && in_array( 1, $this -> api -> user_groups) && !in_array( 1, $appCore -> user['groups']);
		
		// User Not Found
		if ( !$this -> api -> data_loaded)
		{
			// Draw Error
			$appCore -> output -> error( $appCore -> lang['acp_user_not_found'], $appCore -> lang['acp_users_list']);
			
			// Jump back to Users List
			new action_users( $appCore);
		}
		else if ( $appCore -> _REQ( 'do') == 'profile')
		{
			// Get avaiable groups
			$this -> groups = $appCore -> users -> getUserGroups();
			
			// Get Masks
			$this -> masks = $appCore -> getMasks();
				
			// Add empty Rank
			$this -> ranks[0] = $appCore -> lang['rank_use_none'];
			
			// Ranks
			$appCore -> db -> query( 'SELECT rank_id, rank_name FROM ' . DB_PREFIX . 'user_ranks WHERE rank_special = \'1\'');
			
			// Pass them to array
			while ( $rank_result = $appCore -> db -> fetch_array())
			{
				// Pass to array
				$this -> ranks[$rank_result[0]] = ($appCore -> conf['board_int_ranks'] ? $appCore -> ifString( htmlspecialchars( $rank_result[1])) : htmlspecialchars( $rank_result[1]));
			}
			
			// Flush Result
			$appCore -> db -> freeResult();
			
			// Get Styles
			$this -> styles = $appCore -> getStyles( false);
			
			// Get Languages
			$this -> languages = $appCore -> getLanguages();
			
			// Update?
			if ( $appCore -> _POST( 'update') == 1)
			{
				// Set User Posts Counter and rank
				$this -> api -> setUserPosts( $appCore -> _POST( 'user_posts'));
				$this -> api -> setUserRank( $appCore -> _POST( 'user_rank'));
				$this -> api -> setUserTitle( $appCore -> _POST( 'user_title'));
				
				// Set User Timezone and DST
				$this -> api -> setUserTimezone( $appCore -> _POST( 'user_timezone'));
				$this -> api -> setUserDST( $appCore -> _POST( 'user_dst'));
				
				// E-Mail Settings
				$this -> api -> setUserWantEmails( $appCore -> _POST( 'user_want_emails'));
				$this -> api -> setUserShowEmail( $appCore -> _POST( 'user_show_email'));
				$this -> api -> setUserWantMailings( $appCore -> _POST( 'user_want_mailings'));
				
				// Set Style And Language
				$this -> api -> setUserStyle( $appCore -> _POST( 'user_style'));
				$this -> api -> setUserLanguage( $appCore -> _POST( 'user_language'));
				
				// Change Root stuff?
				if ( !$this -> root_secure)
				{
					// Change Log-In
					$this -> api -> setUserLogin( $appCore -> _POST( 'user_login'));
					
					// Change E-Mail
					$this -> api -> setUserEmail( $appCore -> _POST( 'user_email'));
					
					// Get raw arrays
					$group_id = (integer) $appCore -> _POST( 'user_group');
					$other_groups = $appCore -> listInput( 'user_groups', false, array_keys( $this -> groups));
					
					// Add group ID to other groups?
					if ( !in_array( $group_id, $other_groups))
					{
						$other_groups[] = $group_id;	
					}
					
					// Root resigns?
					if ( !in_array( 1, $other_groups) && $appCore -> user['id'] == $this -> api -> user_id)
					{
						// Set Error
						$this -> api -> setError( $appCore -> lang['acp_user_admin_resign']);
					}
				}
				
				// Non-root makes somebody Root?
				if ( !in_array( 1, $appCore -> user['groups']) && in_array( 1, $other_groups))
				{
					// Set Error
					$this -> api -> setError( $appCore -> lang['acp_user_cant_root']);
				}
				
				// Main group Incorrect?
				if ( !isset( $this -> groups[$group_id]))
				{
					// Set Error
					$this -> api -> setError( $appCore -> lang['acp_user_none_groups']);
				}
				
				// Style is messed up?
				if ( !isset( $this -> styles[$this -> api -> user_style]))
				{
					// Set Error
					$this -> api -> setError( $appCore -> lang['acp_user_style_incorrect']);
				}
				
				// Language is messed up?
				if ( !isset( $this -> languages[$this -> api -> user_language]))
				{
					// Set Error
					$this -> api -> setError( $appCore -> lang['acp_user_language_incorrect']);
				}
				
				// Api All-rite?
				if ( $this -> api -> error)
				{
					// Draw Errors
					$appCore -> output -> error( join( '<br />', $this -> api -> errors), $appCore -> lang['acp_user_op_profile']);
					
					// Repeat Form
					$this -> drawProfileForm();
				}
				else
				{
					// Change groups only if we dont have error
					if ( !$this -> root_secure)
					{
						// Update user Groups
						$this -> api -> setGroupId( $group_id);
						$this -> api -> setUserGroups( $other_groups);
						
						// Truncade members table and insert new content
						$appCore -> db -> delete( 'user_groups_members', 'user_id = \'' . $this -> api -> user_id . '\'');
						
						// Make Mass Insert
						$groups_insert = array();
						
						// Reiterate Groups
						foreach ( $other_groups as $group_id)
						{
							$groups_insert[] = '\'' . ((integer) $group_id) . '\', \'' . $this -> api -> user_id . '\'';
						}
						
						// Hit Insert!
						$appCore -> db -> multipleInsert( 'group_id, user_id', $groups_insert, 'user_groups_members');
					}
					
					// Change avatar stuff?
					if ( $this -> api -> user_avatar_type > 0)
					{
						// PWN avatar?
						if ( $appCore -> _POST('user_avatar_delete') == 1)
						{
							// Kill User's Avatar Data
							$this -> api -> deleteUserAvatar();
						}
						else
						{
							// Just update width and height
							$this -> api -> setUserAvatarWidth( $appCore -> _POST('user_avatar_width'));
							$this -> api -> setUserAvatarHeight( $appCore -> _POST('user_avatar_height'));
						}
					}
					
					// Save Api
					$this -> api -> saveData();
					
					// Set Log
					$appCore -> logAdmin( 'log_admin_edited_user_profile', htmlspecialchars( $this -> api -> user_name));
					
					// Redirect us
					$appCore -> output -> drawRedirect( $appCore -> adminLink( strlen( $appCore -> _POST('leave_edition')) > 0 ? 'act=users' : 'act=edit_user&do=profile&user=' . $this -> api -> user_id), $appCore -> lang['acp_user_profile_edited']);
				}
			}
			else
			{
				// Draw Form
				$this -> drawProfileForm();
			}
		}
		else if ( $appCore -> _REQ( 'do') == 'name')
		{
			// Update?
			if ( $appCore -> _POST( 'update') == 1)
			{
				// Set Users Name
				$this -> api -> setUserName( $appCore -> _POST( 'user_name'));
				
				// Error?
				if ( $this -> api -> error)
				{
					// Draw Errors
					$appCore -> output -> error( $this -> api -> last_error, $appCore -> lang['acp_user_op_names']);
					
					// Repeat Form
					$this -> drawNameForm();
				}
				else
				{
					// Save Api
					$this -> api -> saveData();
					
					// Update User Name
					$appCore -> updateUserName( $this -> api -> user_id, $this -> api -> user_name);
					
					// Set Log
					$appCore -> logAdmin( 'log_admin_edited_user_name', htmlspecialchars( $this -> api -> user_name));
					
					// Redirect us
					$appCore -> output -> drawRedirect( $appCore -> adminLink('act=users'), $appCore -> lang['acp_user_name_edited']);
				}
			}
			else
			{
				// Draw Form
				$this -> drawNameForm();
			}
			
		}
		else if ( $appCore -> _REQ( 'do') == 'signature')
		{
			// Update?
			if ( $appCore -> _POST( 'update') == 1)
			{
				// Update API
				$this -> api -> setUserSignatureRaw($appCore -> _POST( 'user_signature'));
				$this -> api -> setUserSignatureSet( $appCore -> getByte( 'user_signature_bbcode') . $appCore -> getByte( 'user_signature_smileys') . $appCore -> getByte( 'user_signature_links'));
				
				// Error?
				if ( $this -> api -> error)
				{
					// Draw Errors
					$appCore -> output -> error( $this -> api -> last_error, $appCore -> lang['acp_user_op_signature']);
					
					// Repeat Form
					$this -> drawSignatureForm();
				}
				else
				{
					// Make Parser
					$parser = new class_parser($appCore, false);
					
					// Parse signature
					$parsed_signature = $parser -> preparse($this -> appCore -> _POST('user_signature'), array(
						'bbcode' 	=> $this -> appCore -> conf['signatures_bbcodes'] && $this -> appCore -> getByte('user_signature_bbcode'),
						'smileys' 	=> $this -> appCore -> conf['signatures_smileys'] && $this -> appCore -> getByte('user_signature_smileys'),
						'urls' 		=> $this -> appCore -> conf['signatures_links'],
						'links' 	=> $this -> appCore -> conf['signatures_links'] && $this -> appCore -> getByte('user_signature_links'),
						'geshi' 	=> $this -> appCore -> conf['signatures_geshi'],
						'images'	=> $this -> appCore -> conf['signatures_images'],
						'youtube' 	=> 0
					));
					
					// Geshi Limit
					if ( $this -> appCore -> conf['signatures_geshi_limit']  > 0 && $parser -> text_geshi > $this -> appCore -> conf['signatures_geshi_limit'])
					{
						// Set Error
						$this -> api -> setError(sprintf($this -> appCore -> lang['user_cp_signature_geshi_limit'], $this -> appCore -> conf['signatures_geshi_limit']));
					}
					
					// Images Limit
					if ( $this -> appCore -> conf['signatures_images_limit']  > 0 && $parser -> text_images > $this -> appCore -> conf['signatures_images_limit'])
					{
						// Set Error
						$this -> api -> setError(sprintf($this -> appCore -> lang['user_cp_signature_images_limit'], $this -> appCore -> conf['signatures_images_limit']));
					}
					
					// Links Limit
					if ( $this -> appCore -> conf['signatures_links_limit']  > 0 && $parser -> text_links > $this -> appCore -> conf['signatures_links_limit'])
					{
						// Set Error
						$this -> api -> setError(sprintf($this -> appCore -> lang['user_cp_signature_links_limit'], $this -> appCore -> conf['signatures_links_limit']));
					}
					
					// Smileys Limit
					if ( $this -> appCore -> conf['signatures_smileys_limit']  > 0 && $parser -> text_smileys > $this -> appCore -> conf['signatures_smileys_limit'])
					{
						// Set Error
						$this -> api -> setError(sprintf($this -> appCore -> lang['user_cp_signature_smileys_limit'], $this -> appCore -> conf['signatures_smileys_limit']));
					}
									
					// Kill Parser
					unset($parser);
					
					// Error?
					if ( $this -> api -> error)
					{
						// Draw Errors
						$appCore -> output -> error( $this -> api -> last_error, $appCore -> lang['acp_user_op_signature']);
						
						// Repeat Form
						$this -> drawSignatureForm();
					}
					else
					{
						// Save New Signature
						$this -> api -> setUserSignature($parsed_signature);
						
						// Save Api
						$this -> api -> saveData();
						
						// Set Log
						$appCore -> logAdmin( 'log_admin_edited_user_signature', htmlspecialchars( $this -> api -> user_name));
						
						// Get back to list?
						if ( strlen( $appCore -> _POST( 'leave_editor')) > 0)
						{
							// Redirect us
							$appCore -> output -> drawRedirect( $appCore -> adminLink('act=users'), $appCore -> lang['acp_user_signature_edited']);
						}
						else
						{
							// Draw Message
							$appCore -> output -> message( $appCore -> lang['acp_user_signature_edited'], $appCore -> lang['acp_user_op_signature']);
						
							// Draw form
							$this -> drawSignatureForm();
						}
					}
				}
			}
			else
			{
				// Draw Form
				$this -> drawSignatureForm();
			}
		}
		else if ( $appCore -> _REQ( 'do') == 'pass')
		{
			// Update?
			if ( $appCore -> _POST( 'update') == 1)
			{
				// Set Users Name
				$this -> api -> setUserPassword( $appCore -> _POST( 'user_password'));
				
				// Error?
				if ( $this -> api -> error)
				{
					// Draw Errors
					$appCore -> output -> error( $this -> api -> last_error, $appCore -> lang['acp_user_op_pass']);
					
					// Repeat Form
					$this -> drawPasswordForm();
				}
				else
				{
					// Save Api
					$this -> api -> saveData();
										
					// Log user out
					$appCore -> db -> update( array( 'user_id' => -1), 'sessions', 'user_id = \'' . $this -> api -> user_id . '\'');
					
					// Set Log
					$appCore -> logAdmin( 'log_admin_edited_user_pass', htmlspecialchars( $this -> api -> user_name));
					
					// Redirect us
					$appCore -> output -> drawRedirect( $appCore -> adminLink('act=users'), $appCore -> lang['acp_user_pass_changed']);
					
					// Notify user?
					if ( $appCore -> _POST('user_notify'))
					{
						// Keep Script Alive
						$appCore -> stayAlive();
						
						// Start our great mailer
						$mailer = new class_mailer( $appCore);
						
						// Send E-Mail
						$mailer -> sendEmail(
							$this -> api -> user_email,
							$this -> api -> user_name,
							$appCore -> lang['email_register_title'],
							class_strings::parseMailText( file_get_contents( CACHE_PATH . 'lang_' . $this -> api -> user_language . '/email_password_reset_adm.txt'), array(
								'{USER_NAME}' 			=> $this -> api -> user_name,
								'{USER_PASSWORD}' 		=> $appCore -> _POST( 'user_password'),
								'{BOARD_NAME}' 			=> $appCore -> conf['board_name'],
								'{BOARD_URL}' 			=> $appCore -> emailLink()
							)));
					}
				}
			}
			else
			{
				// Draw Form
				$this -> drawPasswordForm();
			}
		}
		else if ( $appCore -> _REQ( 'do') == 'prune_keys')
		{
			// Kill All User's Autolog Keys
			$appCore -> db -> delete( 'sessions_keys', 'user_id = \'' . $this -> api -> user_id . '\'');
			
			// Log Action
			$appCore -> logAdmin( 'log_admin_pruned_user_session_keys', htmlspecialchars( $this -> api -> user_name));
					
			// Draw Message
			$appCore -> output -> message( $appCore -> lang['acp_user_session_keys_pruned'], htmlspecialchars( $this -> api -> user_name));
			
			// Jump back to Users List
			new action_users( $appCore);
		}
		else if ( $appCore -> _REQ( 'do') == 'delete')
		{
			// U cannot deletehhh teh root or urself
			if ( in_array( 1, $this -> api -> user_groups))
			{
				// Draw Error
				$appCore -> output -> error( $appCore -> lang['acp_user_delete_root'], $appCore -> lang['acp_user_op_delete_user']);
				
				// Jump back to Users List
				new action_users( $appCore);
			}
			else if ( $this -> api -> user_id == $appCore -> user['id'])
			{
				// Draw Error
				$appCore -> output -> error( $appCore -> lang['acp_user_delete_yourself'], $appCore -> lang['acp_user_op_delete_user']);
				
				// Jump back to Users List
				new action_users( $appCore);
			}
			else
			{
				if ( $appCore -> _POST( 'update') == 1)
				{
					// Confirm Deletion?
					if ( $appCore -> _POST('user_delete') == 1)
					{
						// Pown solo user
						$appCore -> users -> deleteUsers( array( $this -> api -> user_id => $this -> api -> user_name));		
						
						// Log Action
						$appCore -> logAdmin( 'log_admin_deleted_user', htmlspecialchars( $this -> api -> user_name));
					
						// Redirect us
						$appCore -> output -> drawRedirect( $appCore -> adminLink('act=users'), $appCore -> lang['acp_user_deleted']);	
					}
					else
					{
						// Redirect us
						$appCore -> output -> drawRedirect( $appCore -> adminLink('act=users'), $appCore -> lang['acp_user_not_deleted']);	
					}
				}
				else
				{
					// Draw Form
					$this -> drawDeleteForm();
				}
			}
		}
		else
		{
			// Draw Error
			$appCore -> output -> error( $appCore -> lang['wrong_action_code'], $appCore -> lang['acp_users_list']);
			
			// Jump back to Users List
			new action_users( $appCore);
		}
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Draws Profile Edit Form
	 *
	 */
	
	function drawProfileForm(){
		
		// Load fields templates
		$this -> appCore -> templates['form_inputs'] = new tpl_form_inputs( $this -> appCore);
				
		// Cache output
		ob_start();
				
		// Open Form
		echo $this -> appCore -> output -> openForm( $this -> appCore -> adminLink( 'act=edit_user&do=profile&user=' . $this -> api -> user_id));
		echo $this -> appCore -> drawHidden( 'update', 1);
		echo $this -> appCore -> output -> openFormBlock( $this -> appCore -> lang['acp_user_form_sect_activity_preview']);
		
		// Draw Fields
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_join'], $this-> appCore -> getDate( $this -> api -> user_join_date, 'long'), $this -> api -> user_join_ip);
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_last'], $this-> appCore -> getDate( $this -> api -> user_last_date, 'long'), $this -> api -> user_last_ip);
		
		// New block
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> openFormBlock( $this -> appCore -> lang['acp_user_form_sect_basic']);
		
		// Draw Fields
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_login'], ( $this -> root_secure ? htmlspecialchars( $this -> api -> user_login) : $this-> appCore -> drawTextInput( 'user_login', $this -> api -> user_login)));
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_email'], ( $this -> root_secure ? htmlspecialchars( $this -> api -> user_email) : $this-> appCore -> drawTextInput( 'user_email', $this -> api -> user_email)));
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_posts'], $this-> appCore -> drawTextInput( 'user_posts', $this -> api -> user_posts));
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_rank'], $this-> appCore -> drawList( 'user_rank', $this -> ranks, $this -> api -> user_rank));
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_title'], $this-> appCore -> drawTextInput( 'user_title', $this -> api -> user_title));
			
		// New block
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> openFormBlock( $this -> appCore -> lang['acp_user_form_sect_groups']);
		
		// Allow us mess with user\'s groups?
		if ( $this -> root_secure)
		{
			// User Other groups
			$user_groups = '';
			
			// Iterate memberships
			foreach ( $this -> api -> user_groups as $group_id)
			{
				if ( isset( $this -> groups[$group_id]) && $group_id != $this -> api -> group_id)
				{
					$user_groups .= '<div><b>' . $this -> groups[$group_id] . '</b></div>';
				}
			}
			
			// Draw fields
			echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_group'], '<b>' . $this -> groups[$this -> api -> group_id] . '</b>', $this -> appCore -> lang['acp_user_form_option_blocked']);
			echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_groups'], ( isset($user_groups[0]) ? $user_groups : $this -> appCore -> lang['acp_user_form_groups_none']), $this -> appCore -> lang['acp_user_form_option_blocked']);
		}
		else
		{
			// Remove Registered from other Groups?
			unset( $this -> api -> user_groups[array_search( $this -> api -> group_id, $this -> api -> user_groups)]);
			
			// Draw fields
			echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_group'], $this-> appCore -> drawList( 'user_group', $this -> groups, $this -> api -> group_id));
			echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_groups'], $this-> appCore -> drawMultiList( 'user_groups', $this -> groups, $this -> api -> user_groups));
		}
		
		// Draw masks
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_masks'], $this-> appCore -> drawMultiList( 'user_masks', $this -> masks, $this -> api -> user_masks));
			
		// Draw avatar?
		if ( $this -> api -> user_avatar_type > 0)
		{	
			// New block
			echo $this -> appCore -> output -> closeFormBlock();
			echo $this -> appCore -> output -> openFormBlock( $this -> appCore -> lang['acp_user_form_sect_avatar']);
			
			// Avatar Preview
			echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_avatar_preview'], '<img src="' . class_users::avatarLocation($this -> api -> user_avatar_type) . htmlspecialchars( $this -> api -> user_avatar_image) . '" title="' . htmlspecialchars( $this -> appCore -> lang['user_avatar']) . '" alt="' . htmlspecialchars( $this -> appCore -> lang['user_avatar']) . '" width="' . $this -> api -> user_avatar_width . '" height="' . $this -> api -> user_avatar_height . '"/>', $this -> appCore -> lang['acp_user_form_avatar_type_' . $this -> api -> user_avatar_type] . ' - ' . htmlspecialchars( $this -> api -> user_avatar_image) . ' (' . $this -> api -> user_avatar_width . ' x ' . $this -> api -> user_avatar_height . ')');
			
			// Avatar stuff
			echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_avatar_dimensions'], $this-> appCore -> drawTextInput( 'user_avatar_width', $this -> api -> user_avatar_width, '30px') . ' x ' . $this-> appCore -> drawTextInput( 'user_avatar_height', $this -> api -> user_avatar_height, '30px'));
			echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_avatar_delete'], $this-> appCore -> drawYesNo( 'user_avatar_delete', $this -> appCore -> _POST('user_avatar_delete')), $this -> appCore -> lang['acp_user_form_avatar_delete_expl']);
		}
		
		// New block
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> openFormBlock( $this -> appCore -> lang['acp_user_form_sect_board']);
		
		// User Timezone and DST
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_timezone'], $this-> appCore -> drawList( 'user_timezone', $this -> appCore -> getTimezones(), $this -> api -> user_timezone));
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_dst'], $this-> appCore -> drawYesNo( 'user_dst', $this -> api -> user_dst));
		
		// New block
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> openFormBlock();
				
		// E-Mail Settings
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_want_emails'], $this-> appCore -> drawYesNo( 'user_want_emails', $this -> api -> user_want_emails));
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_show_email'], $this-> appCore -> drawYesNo( 'user_show_email', $this -> api -> user_show_email));
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_want_mailings'], $this-> appCore -> drawYesNo( 'user_want_mailings', $this -> api -> user_want_mailings));
		
		// New block
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> openFormBlock();
		
		// User Style and Language
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_style'], $this-> appCore -> drawList( 'user_style', $this -> styles, $this -> api -> user_style));
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_language'], $this-> appCore -> drawList( 'user_language', $this -> languages, $this -> api -> user_language));
			
		// Close Form
		echo $this -> appCore -> output -> submitButton( $this -> appCore -> lang['save_changes'], $this -> appCore -> drawButton( 'leave_edition', $this -> appCore -> lang['save_and_leave']));
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> closeForm();
		
		// Draw output
		$this -> appCore -> output -> draw( $this -> appCore -> lang['acp_user_op_profile'], array(
			$this -> appCore -> adminLink( 'act=users') => $this -> appCore -> lang['acp_users_list'],
			'' => htmlspecialchars( $this -> api -> user_name)
		), ob_get_clean());
			
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Draws User Rename Form
	 *
	 */
	
	function drawNameForm(){
			
		// Load fields templates
		$this -> appCore -> templates['form_inputs'] = new tpl_form_inputs( $this -> appCore);
				
		// Cache output
		ob_start();
				
		// Open Form
		echo $this -> appCore -> output -> openForm( $this -> appCore -> adminLink( 'act=edit_user&do=name&user=' . $this -> api -> user_id));
		echo $this -> appCore -> drawHidden( 'update', 1);
		echo $this -> appCore -> output -> openFormBlock();
		
		// Draw Field
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_name'], $this-> appCore -> drawTextInput( 'user_name', $this -> api -> user_name));
		
		// Close Form
		echo $this -> appCore -> output -> submitButton( $this -> appCore -> lang['save_changes']);
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> closeForm();
		
		// Draw output
		$this -> appCore -> output -> draw( $this -> appCore -> lang['acp_user_op_names'], array(
			$this -> appCore -> adminLink( 'act=users') => $this -> appCore -> lang['acp_users_list'],
			'' => htmlspecialchars( $this -> api -> user_name)
		), ob_get_clean());
		
	}

	// ------------------------------------------------------------------------

	/**
	 * Draws User Signature Edition Form
	 *
	 */
	
	function drawSignatureForm(){
			
		// Load fields templates
		$this -> appCore -> templates['form_inputs'] = new tpl_form_inputs( $this -> appCore);
				
		// Cache output
		ob_start();
				
		// Open Form
		echo $this -> appCore -> output -> openForm( $this -> appCore -> adminLink( 'act=edit_user&do=signature&user=' . $this -> api -> user_id));
		echo $this -> appCore -> drawHidden( 'update', 1);
		echo $this -> appCore -> output -> openFormBlock();
		
		// Draw Field
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_signature'], $this-> appCore -> drawTextArea( 'user_signature', $this -> api -> user_signature_raw) . $this -> appCore -> output -> parsingOps( 'user_signature', true, true, true, $this -> api -> user_signature_set[0], $this -> api -> user_signature_set[1], $this -> api -> user_signature_set[2]));
		
		// Close Form
		echo $this -> appCore -> output -> submitButton( $this -> appCore -> lang['save_changes'], $this -> appCore -> drawButton( 'leave_editor', $this -> appCore -> lang['save_and_leave']));
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> closeForm();
		
		// Draw output
		$this -> appCore -> output -> draw( $this -> appCore -> lang['acp_user_op_signature'], array(
			$this -> appCore -> adminLink( 'act=users') => $this -> appCore -> lang['acp_users_list'],
			'' => htmlspecialchars( $this -> api -> user_name)
		), ob_get_clean());
		
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Draws User Password Form
	 *
	 */
	
	function drawPasswordForm(){
			
		// Load fields templates
		$this -> appCore -> templates['form_inputs'] = new tpl_form_inputs( $this -> appCore);
				
		// Cache output
		ob_start();
				
		// Open Form
		echo $this -> appCore -> output -> openForm( $this -> appCore -> adminLink( 'act=edit_user&do=pass&user=' . $this -> api -> user_id));
		echo $this -> appCore -> drawHidden( 'update', 1);
		echo $this -> appCore -> output -> openFormBlock();
		
		// Draw Field
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_password_new'], $this-> appCore -> drawPassInput( 'user_password', $this -> appCore -> _POST('user_password')));
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_notify_pass'], $this-> appCore -> drawYesNo( 'user_notify', $this -> appCore -> _POST('user_notify')), $this -> appCore -> lang['acp_user_form_notify_pass_expl']);
		
		// Close Form
		echo $this -> appCore -> output -> submitButton( $this -> appCore -> lang['save_changes']);
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> closeForm();
		
		// Draw output
		$this -> appCore -> output -> draw( $this -> appCore -> lang['acp_user_op_pass'], array(
			$this -> appCore -> adminLink( 'act=users') => $this -> appCore -> lang['acp_users_list'],
			'' => htmlspecialchars( $this -> api -> user_name)
		), ob_get_clean());
		
	}

	// ------------------------------------------------------------------------

	/**
	 * Draws User Delete Form
	 *
	 */
	
	function drawDeleteForm(){
			
		// Load fields templates
		$this -> appCore -> templates['form_inputs'] = new tpl_form_inputs( $this -> appCore);
				
		// Cache output
		ob_start();
				
		// Open Form
		echo $this -> appCore -> output -> openForm( $this -> appCore -> adminLink( 'act=edit_user&do=delete&user=' . $this -> api -> user_id));
		echo $this -> appCore -> drawHidden( 'update', 1);
		echo $this -> appCore -> output -> openFormBlock();
		
		// Draw Field
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['acp_user_form_confirm_deletion'], $this-> appCore -> drawYesNo( 'user_delete', 0), $this -> appCore -> lang['acp_user_form_confirm_deletion_expl']);
		
		// Close Form
		echo $this -> appCore -> output -> submitButton( $this -> appCore -> lang['send']);
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> closeForm();
		
		// Draw output
		$this -> appCore -> output -> draw( $this -> appCore -> lang['acp_user_op_delete_user'], array(
			$this -> appCore -> adminLink( 'act=users') => $this -> appCore -> lang['acp_users_list'],
			'' => htmlspecialchars( $this -> api -> user_name)
		), ob_get_clean());
		
	}

}